package com.sogoodsoft.service.crm;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class OrderThread extends Thread {

	protected static String mysqlDriver = "com.mysql.jdbc.Driver";
	protected static String mysqlUser="sogoodsoft";
	protected static String mysqlPasswd = "sogoodsoft";
	protected static String mysqlUrl = "jdbc:mysql://localhost/sogoodsoft?useUnicode=true&characterEncoding=utf-8";
	Connection conn;
	public OrderThread(){
		
		try {
			Class.forName(mysqlDriver);
			 conn = DriverManager.getConnection(mysqlUrl, mysqlUser, mysqlPasswd);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	
	
	public void run(){
		try {
			conn.setAutoCommit(false);
			Statement stat = conn.createStatement();
			for(int i=0;i<50;i++){
				System.out.println("insert into sss(nono) values('"+OrderSerialService.getSerial()+"');");				
				stat.addBatch("insert into sss(nono) values('"+OrderSerialService.getSerial()+"')");
				sleep(100);
			}
			stat.executeBatch();
			conn.commit();
			stat.close();
			conn.close();
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
		
	}
}
